package algorithms.leecode;
public class Au134 {
    public static void main(String[] args) {
        int[] gas = {2,3,4};
        int[] cost = {3,4,3};

        int sum = 0;
        int start = 0;
        int curSum = 0;
        for (int i = 0; i < gas.length; i++) {
            sum+= gas[i] - cost[i];
            curSum += gas[i] - cost[i];
            if (curSum < 0) {
                start = i + 1;
                curSum = 0;
            }
        }
        if (sum <0) {
            System.err.println(-1);
        }
        System.err.println(start);

    }

}
